/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */



import java.sql.CallableStatement;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;

/**
 *
 * @author spthanh
 */
public class Procedure_Example2 {
    public static void main(String[] args){
        try{
            Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver");
            Connection con = DriverManager.getConnection("jdbc:sqlserver://localhost:1433;databaseName=AdventureWorks", "sa", "123");

//            String query = "CREATE Procedure proc_GetEmpl " +
//                           " AS" +
//                           "    BEGIN" +
//                            "         SELECT EmployeeID , LoginID, Title, ManagerID , Gender , VacationHours " +
//                            "         FROM HumanResources.Employee " +
//                           "    END ";

             CallableStatement cst = con.prepareCall("{call proc_GetEmpl }");
             ResultSet rs = cst.executeQuery();

             while(rs.next()){
                 System.out.println("Employee ID:" + rs.getString("EmployeeID"));
                 System.out.println("Title :" + rs.getString("Title"));
                 System.out.println("Gender :" + rs.getString("Gender"));
                 System.out.println("Vacation Hours:" + rs.getInt("VacationHours"));

             }

        }
        catch(Exception e){
            e.printStackTrace();
        }
    }
}
